﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MarginTrading.Services;
using Microsoft.Reporting.WinForms;
using MarginTrading.Entity;
using MarginTrading.Common;

namespace MarginTrading.Forms
{
    public partial class StockWiseHolding : Form
    {
        public StockWiseHolding()
        {
            InitializeComponent();
        }

        private void StockWiseHolding_Load(object sender, EventArgs e)
        {
            try
            {
                DataTable advisor = AdvisorServices.GetAdvisorCollectionDataTable();
                DataRow dr = advisor.NewRow();
                dr["CODE"] = "All";
                advisor.Rows.InsertAt(dr, 0);
                AdvisorComboBox.DisplayMember = "CODE";
                AdvisorComboBox.ValueMember = "CODE";
                AdvisorComboBox.DataSource = advisor;


                DataTable Stock = SecurityServices.GetSecurityCollectionDataTable();
                StockComboBox.DisplayMember = "SYMBOL";
                StockComboBox.ValueMember = "SYMBOL";
                StockComboBox.DataSource = Stock;
            }
            catch (Exception x)
            {
            }

        }

        private void SearchBtn_Click(object sender, EventArgs e)
        {
            try
            {
                LoadReport(AdvisorComboBox.SelectedValue.ToString(), StockComboBox.SelectedValue.ToString());
                //LoadReport1();
            }
            catch (System.Exception ex)
            {
            	
            }
            
        }

//         private void LoadReport1()
//         {
//             try
//             {
// 
//                 Config AgentCodeConfig = ConfigServices.GetConfigByName("Agent Code");
//                 ReportDataSource ds = new ReportDataSource();
//                 ds.Name = "master";
//                 ds.Value = ReportServices.LoanBalance();
// 
// 
//                 this.reportViewer1.LocalReport.ReportPath = "LoanBalance.rdlc";
//                 this.reportViewer1.LocalReport.DataSources.Clear();
//                 this.reportViewer1.LocalReport.DataSources.Add(ds);
// 
// 
//                 string AgentCode = "cts";
//                 if (AgentCodeConfig != null)
//                 {
//                     AgentCode = AgentCodeConfig.Value;
//                 }
// 
//                 //TODO:Remove this 
//                 AgentCode = Reports.AGENT_CODE;
// 
//                 this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] {
//                         new ReportParameter("ImageLink",AgentCode.ToLower()),
//                         new ReportParameter("CompanyName",Reports.COMPANY_NAME),
//                         new ReportParameter("StockCode", "Stock"),
//                         new ReportParameter("AdvisorID","sAdvisor")});
// 
//                 this.reportViewer1.RefreshReport();
//                 reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
//                 reportViewer1.ZoomMode = ZoomMode.Percent;
//                 reportViewer1.ZoomPercent = 100;
//             }
//             catch (Exception e)
//             {
//                 MessageBox.Show(e.Message);
//             }
// 
//         }


        private void LoadReport(string sAdvisor, String Stock)
        {
            try
            {

                Config AgentCodeConfig = ConfigServices.GetConfigByName("Agent Code");

                ReportDataSource ds = new ReportDataSource();
                ds.Name = "master";
                ds.Value = ReportServices.GetStockwiseHolding(AgentCodeConfig.Value, sAdvisor, Stock);


                this.reportViewer1.LocalReport.ReportPath = "StockWiseHolding.rdlc";
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.DataSources.Add(ds);


                string AgentCode = "cts";
                if (AgentCodeConfig != null)
                {
                    AgentCode = AgentCodeConfig.Value;
                }

                //TODO:Remove this 
                AgentCode = Reports.AGENT_CODE;

                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] {
                        new ReportParameter("ImageLink",AgentCode.ToLower()),
                        new ReportParameter("CompanyName",Reports.COMPANY_NAME),
                        new ReportParameter("StockCode", Stock),
                        new ReportParameter("AdvisorID",sAdvisor)});

                this.reportViewer1.RefreshReport();
                reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
                reportViewer1.ZoomMode = ZoomMode.Percent;
                reportViewer1.ZoomPercent = 100;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

        }
    }
}
